package ex.datastream.functions.dataStream;

import ex.datastream.functions.function.FlatMapFuncBySplitter01;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


/**
 * 按分组进行值累加
 */
public class KeByTest {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStream<String> text = env.fromElements(
                "a a b ",
                "c b"
        );
        text.flatMap(new FlatMapFuncBySplitter01())
                .keyBy(v->v.f0)
                .sum(1).printToErr();
        env.execute();
    }
//(a,1)
//(a,2)
//(b,1)
//(c,1)
//(b,2)

}
